package com.uobgroup.ews.uam.core.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
@NamedQueries({ @NamedQuery(name = "Segment.findSegmentById", query = "SELECT S FROM Segment S WHERE S.id = :segmentId") })
public class Segment extends BaseEntity implements SecurityGroupAware {

   public static final String QUERY_FIND_SEGMENT_BY_ID = "Segment.findSegmentById";

   public static final String PARAM_SEGMENT_ID = "segmentId";

   @OneToOne(cascade = CascadeType.REMOVE)
   private Reference segmentReference;

   @OneToOne(cascade = CascadeType.PERSIST)
   private SecurityGroup securityGroup;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   private Long id;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Reference getSegmentReference() {
      return this.segmentReference;
   }

   public void setSegmentReference(Reference segmentReference) {
      this.segmentReference = segmentReference;
   }

   public SecurityGroup getSecurityGroup() {
      return this.securityGroup;
   }

   public void setSecurityGroup(SecurityGroup securityGroup) {
      this.securityGroup = securityGroup;
   }

   @Override
   public String getSecurityGroupName() {
      return segmentReference.getName();
   }

   @Override
   public String getParentGroupName() {
      return "segment";
   }
}
